#include<bits/stdc++.h>
using namespace std;
long long T,n,m,l,V,p[100001],chk,ans,nxt[100001],pos,A,B,C,POS,P[100001];
struct CAR
{
	long long d,v,a;
	bool operator<(const CAR &Y)const
	{
		return d<Y.d;
	}
}car[100001];
bool check()
{
	long long CHK=0,Pos=POS;
	for(int i=n;i>=1;i--)
	{
		while(P[Pos-1]>=car[i].d&&Pos>1)
		{
			Pos--;
		}
		nxt[i]=Pos;
	}
	for(int i=1;i<=n;i++)
	{
		if(car[i].a==0)
		{
			if(car[i].v>V)
			{
				if(car[i].d<=P[POS])
				{
					CHK++;
				}
			}
		}
		else if(car[i].a>0)
		{
			if(car[i].d<=P[POS])
			{
				if(car[i].v*car[i].v+2*car[i].a*(P[POS]-car[i].d)>V*V)
				{
					CHK++;
				}
			}
		}
		else
		{
			if(car[i].d<=P[POS])
			{
				if(car[i].v*car[i].v+2*car[i].a*(P[nxt[i]]-car[i].d)>V*V)
				{
					CHK++;
				}
			}
		}
	}
	return CHK==chk;
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	scanf("%lld",&T);
	for(int z=1;z<=T;z++)
	{
		scanf("%lld%lld%lld%lld",&n,&m,&l,&V);
		A=0,B=0,C=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld%lld%lld",&car[i].d,&car[i].v,&car[i].a);
			if(car[i].a==0)
			{
				A++;
			}
			else if(car[i].a>0)
			{
				B++;
			}
			else
			{
				C++;
			}
		}
		for(int i=1;i<=m;i++)
		{
			scanf("%lld",&p[i]);
		}
		sort(car+1,car+n+1);
		sort(p+1,p+m+1);
		chk=0,ans=INT_MAX,pos=m;
		for(int i=n;i>=1;i--)
		{
			while(p[pos-1]>=car[i].d&&pos>1)
			{
				pos--;
			}
			nxt[i]=pos;
		}
		for(int i=1;i<=n;i++)
		{
			if(car[i].a==0)
			{
				if(car[i].v>V)
				{
					if(car[i].d<=p[m])
					{
						chk++;
					}
				}
			}
			else if(car[i].a>0)
			{
				if(car[i].d<=p[m])
				{
					if(car[i].v*car[i].v+2*car[i].a*(p[m]-car[i].d)>V*V)
					{
						chk++;
					}
				}
			}
			else
			{
				if(car[i].d<=p[m])
				{
					if(car[i].v*car[i].v+2*car[i].a*(p[nxt[i]]-car[i].d)>V*V)
					{
						chk++;
					}
				}
			}
		}
		if(A==n||B==n)
		{
			printf("%lld %lld\n",chk,m-1+(chk==0));
			continue;
		}
		for(int i=1;i<(1<<m);i++)
		{
			POS=0;
			for(int j=0;j<m;j++)
			{
				if(i>>j&1)
				{
					P[++POS]=p[j+1];
				}
			}
			if(POS>=ans)
			{
				continue;
			}
			if(check())
			{
				ans=POS;
			}
		}
		printf("%lld %lld\n",chk,m-ans);
	}
	return 0;
}
